// 摩尔投票法
var majorityElement = function (nums) {
  let res = nums[0],
      count = 1;
  for (let i = 1; i < nums.length; i++) {
    if (res == nums[i]) {
      count++;
    } else if (--count == 0) {
      res = nums[i];
      count = 1;
    }
  }
  return res;
}